//
// Description: 383. 赎金信
// Created by Loading on 2021/12/4.
//

#include <bits/stdc++.h>

using namespace std;

bool canConstruct(string ransomNote, string magazine) {
    // 赎金信长度大于杂志长度，一定不能构成
    if (ransomNote.size() > magazine.size()) {
        return false;
    }

    unordered_map<int, int> m;
    for (auto &c : magazine) {
        m[c]++;
    }
    for (auto &c : ransomNote) {
        m[c]--;
        if (m[c] < 0) {
            return false;
        }
    }

    return true;
}

int main() {
    string ransomNote = "aab";
    string magazine = "ab";
    bool res = canConstruct(ransomNote, magazine);
    cout << res << endl;

    return 0;
}